package com.springcloud.demo.service;

import com.springcloud.demo.api.DemoRpcService;
import com.springcloud.demo.dao.DemoDao;
import com.springcloud.demo.model.Demo;
import com.xframework.exception.BusinessException;
import com.xframework.exception.ExceptionCode;
import com.xframework.service.BaseService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Created by xuning on 2020/8/26.
 */
@DubboService
@Component
public class DemoService extends BaseService implements DemoRpcService {

    @Autowired
    private DemoDao demoDao;

    @Override
    public Demo helloDemoProvider(Demo demo) {
        try {
            System.out.println("DemoService demoId=" + demo.getDemoId());
            System.out.println("DemoService demoId=" + demo.getDemoName());
            List<Demo> list = demoDao.selectDemoList(demo);
            demo = list.get(0);
            return demo;
        } catch (Exception e) {
            throw new BusinessException(ExceptionCode.EXCEPTION_CODE0000, e);
        }
    }

}
